/**
 * @(#)Email.java 2010-2-22
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.entity;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;

/**
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class Email implements Serializable {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 7220819525550737744L;
	private Address fromAddress;
	private Address[] toAddress;
	private Address[] ccAddress;
	private Address[] bccAddress;
	private String subject;
	private String emailBody;
	private File[] attachments;

	public Email(Message message) {
		try {
			this.ccAddress = message.getRecipients(RecipientType.CC);
			this.bccAddress = message.getRecipients(RecipientType.BCC);
			this.toAddress = message.getRecipients(RecipientType.TO);
			this.subject = message.getSubject();
			this.emailBody = message.getContent().toString();
		} catch (MessagingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 完整构造函数
	 * 
	 * @param fromAddress
	 *            发件地址
	 * @param toAddress
	 *            收件地址
	 * @param ccAddress
	 *            抄送地址
	 * @param bccAddress
	 *            密件抄送地址
	 * @param subject
	 *            邮件标题
	 * @param emailBody
	 *            邮件内容
	 * @param attachments
	 *            邮件附件
	 */
	public Email(InternetAddress fromAddress, InternetAddress[] toAddress,
			InternetAddress[] ccAddress, InternetAddress[] bccAddress,
			String subject, String emailBody, File[] attachments) {
		super();
		this.fromAddress = fromAddress;
		this.toAddress = toAddress;
		this.ccAddress = ccAddress;
		this.bccAddress = bccAddress;
		this.subject = subject;
		this.emailBody = emailBody;
		this.attachments = attachments;
	}

	/**
	 * 默认构造函数
	 */
	public Email() {
		super();
	}

	/**
	 * 最小化构造函数
	 * 
	 * @param subject
	 *            邮件标题
	 * @param emailBody
	 *            邮件内容
	 */
	public Email(String subject, String emailBody) {
		super();
		this.subject = subject;
		this.emailBody = emailBody;
	}

	/**
	 * @return the fromAddress
	 */
	public Address getFromAddress() {
		return fromAddress;
	}

	/**
	 * @param fromAddress
	 *            the fromAddress to set
	 */
	public void setFromAddress(Address fromAddress) {
		this.fromAddress = fromAddress;
	}

	/**
	 * @return the toAddress
	 */
	public Address[] getToAddress() {
		return toAddress;
	}

	/**
	 * @param toAddress
	 *            the toAddress to set
	 */
	public void setToAddress(Address[] toAddress) {
		this.toAddress = toAddress;
	}

	/**
	 * @return the ccAddress
	 */
	public Address[] getCcAddress() {
		return ccAddress;
	}

	/**
	 * @param ccAddress
	 *            the ccAddress to set
	 */
	public void setCcAddress(Address[] ccAddress) {
		this.ccAddress = ccAddress;
	}

	/**
	 * @return the bccAddress
	 */
	public Address[] getBccAddress() {
		return bccAddress;
	}

	/**
	 * @param bccAddress
	 *            the bccAddress to set
	 */
	public void setBccAddress(Address[] bccAddress) {
		this.bccAddress = bccAddress;
	}

	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * @param subject
	 *            the subject to set
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 * @return the attachments
	 */
	public File[] getAttachments() {
		return attachments;
	}

	/**
	 * @param attachments
	 *            the attachments to set
	 */
	public void setAttachments(File[] attachments) {
		this.attachments = attachments;
	}

	/**
	 * @return the emailBody
	 */
	public String getEmailBody() {
		return emailBody;
	}

	/**
	 * @param emailBody
	 *            the emailBody to set
	 */
	public void setEmailBody(String emailBody) {
		this.emailBody = emailBody;
	}
}
